package usersManagement.service;

import org.slf4j.Logger;
import usersManagement.model.User;
import usersManagement.util.AppLog;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

/**
 * User: eluibon
 * Date: 11/12/12
 * Time: 14.06
 */
@Stateless
public class AccessService {

    @Inject @AppLog Logger log;

    @Inject @PersistenceContext EntityManager em;


    public User findUserByUsername(String username) {

        try {
            return em.createNamedQuery("findUserByUsername",User.class).setParameter("username",username).getSingleResult() ;
        }
        catch (NoResultException nre) {
            log.debug("No user found for username : {}", username);
        }
        return null ;
    }

}
